<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_JQuerySparkline
 * @copyright  Copyright (c) 2008-2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: JQuerySparkline.php 7 2009-11-14 22:42:08Z nkeyes $
 */

 class Bushido_JQuerySparkline implements Bushido_Datagram_Visitor
 {
	/**
	 * 
	 * @return void
	 */
 	public function __construct(){}
	
 	/**
 	 * 
 	 * @return void
 	 */
	public function __clone(){}
	
	
	/**
	 * 
	 * @param $chart
	 * @return string
	 */
	public static function  getChart(Bushido_Datagram_Abstract $chart)
	{
		$sparklines = array();
		
		$sparklineOptionsObj = new StdClass();
		$sparklineOptionsObj->composite = true;
		$sparklineOptionsObj->fillColor = false;

		$sparklineOptionsObj->spotColor = false;
		$sparklineOptionsObj->minSpotColor = false;
		$sparklineOptionsObj->maxSpotColor = false;
		
		$sparklineOptionsObj->height = 75;
		
		$dataSeriesList = $chart->getRawData();
		
		foreach($dataSeriesList as $dataSeries)
		{
			$sparklineParams = array();
			
			$dataSeriesValues = array();
			foreach($dataSeries['data'] as $dataSeriesData)
			{
				$dataSeriesValues[] = $dataSeriesData['value'];
			}
			
			$sparklineParams['chartName'] = $chart->getChartName();
			$sparklineParams['values'] = Zend_Json::encode($dataSeriesValues);
			$sparklineOptionsObj->lineColor = '#'. str_pad(dechex(mt_rand(0, 256)), 2, '0', STR_PAD_LEFT)
											. str_pad(dechex(mt_rand(0, 256)), 2, '0', STR_PAD_LEFT)
											. str_pad(dechex(mt_rand(0, 256)), 2, '0', STR_PAD_LEFT);
			$sparklineParams['options'] = Zend_Json::encode($sparklineOptionsObj);
			
			$sparklines[] = $sparklineParams;
		}
		//var_dump($sparklines);exit(0);
		return $sparklines;
	}
	
	/**
	 * 
	 * @param $chart
	 * @return string
	 */
	public static function getChartXML(Bushido_Datagram_Abstract $chart)
	{
		return NULL;
	}
 }
